home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 7 / 007.d81 / dos #15 < prev    next >
Text File  |  2022-08-26  |  3KB  |  196 lines

  1.        DOS & DON'ts -- Part 15
  2.        {CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}
  3.  
  4.          by : Alan W. Gardner
  5.  
  6.  
  7.   This month we will attempt to 'leap'
  8.  
  9. into the world of RANDOM DISK ACCESS.
  10.  
  11.  
  12.   First of all, we need to know some-
  13.  
  14. things about that little magnetic
  15.  
  16. thing we all call a DISK.  We have
  17.  
  18. probably all heard the parallel of a
  19.  
  20. disk to a musical record or LP.  Both
  21.  
  22. have concentric circles which contain
  23.  
  24. DATA.  On a disk, these 'circles' are
  25.  
  26. divided into SECTORS or BLOCKS.  From
  27.  
  28. now on, we will refer to these as
  29.  
  30. SECTORS.  Sectors can be thought of
  31.  
  32. as 'buckets' of information which ride
  33.  
  34. along the disk on their respective
  35.  
  36. TRACKS.  Each track contains a certain
  37.  
  38. number of 'buckets' or SECTORS of
  39.  
  40. information.  These numbers are as
  41.  
  42. follows:
  43.  
  44.  
  45.                                TOTAL
  46.                                #  of
  47. TRACK NUMBER   SECTOR RANGE   SECTORS
  48. {CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}
  49.  1 to 17         0 to 20        21
  50. 18 to 24         0 to 18        19
  51. 25 to 30         0 to 17        18
  52. 31 to 35         0 to 16        17
  53.  
  54.  
  55.  
  56.    We can see that as the TRACK number
  57.  
  58. goes up, there are fewer SECTORS or
  59.  
  60. 'buckets' available for that TRACK.
  61.  
  62. This is because the higher numbered
  63.  
  64. tracks lie toward the center of the
  65.  
  66. disk.  Because of this, the physical
  67.  
  68. size of the track is smaller,
  69.  
  70. therefore the amount of data which
  71.  
  72. can be stored is less.  Thus, the
  73.  
  74. number of SECTORS, or 'buckets' is
  75.  
  76. less.
  77.  
  78.   Now where does that get us??  Well
  79.  
  80. to use RANDOM ACCESS, all of this is
  81.  
  82. very important!
  83.  
  84.   On a single disk, there are 664
  85.  
  86. SECTORS free to use for data and/or
  87.  
  88. programs.  By using RANDOM ACCESS,
  89.  
  90. you can 'tap into' all of this
  91.  
  92. storage.
  93.  
  94.   Now on to the REAL STUFF!!
  95.  
  96.  
  97.   To use RANDOM ACCESS, you must have
  98.  
  99. two files open - the Command/Error
  100.  
  101. channel and a channel to send the
  102.  
  103. DATA through.  To open a channel for
  104.  
  105. DATA transfer the pound sign '#' is
  106.  
  107. used:
  108.  
  109.  10 OPEN15,8,1   : rem command/error
  110.  20 OPEN2,8,2,"#": rem DATA buffer
  111.  
  112.  
  113.   Now once you have both of these
  114.  
  115. channels open, I bet you want to send
  116.  
  117. DATA through them.  Well to do this
  118.  
  119. you first have to 'fill up' your
  120.  
  121. DATA buffer with the information you
  122.  
  123. want to write to the disk.  This is
  124.  
  125. done with the PRINT# statement.  For
  126.  
  127. example:
  128.  
  129.  
  130.    10 OPEN15,8,15   : rem error/comm
  131.    20 OPEN2,8,2,"#" : rem DATA buffer
  132.    30 :
  133.    40 FOR X = 1 to 10
  134.    50 PRINT#2,"THIS IS DATA"
  135.    60 NEXT X
  136.  
  137.  
  138.   This small program segment OPEN's
  139.  
  140. the two channels necessary and then
  141.  
  142. PRINT's the string 'THIS IS DATA'
  143.  
  144. to the DATA buffer ten times.  Now
  145.  
  146. none of what we have done yet has
  147.  
  148. actually WRITTEN anything to the
  149.  
  150. disk.  Before we can do this, we must
  151.  
  152. 'find' a place to 'put' it.  This is
  153.  
  154. done with the BLOCK-ALLOCATE command.
  155.  
  156. The B-A command checks to see if you
  157.  
  158. you can put your data where you told
  159.  
  160. your disk-drive to put it.  If after
  161.  
  162. reading the error channel, you come up
  163.  
  164. with an ERROR #65 - NO BLOCK, then
  165.  
  166. you can't put your data there!!  You
  167.  
  168. have to find a different place to put
  169.  
  170. it.  Well, this is where your C-64
  171.  
  172. really helps you out.  When you get
  173.  
  174. that ERROR #65, your Commodore is also
  175.  
  176. telling you another place to put your
  177.  
  178. data.  When you read the Error channel
  179.  
  180. you usually INPUT four different
  181.  
  182. variables.  The last two tell you the
  183.  
  184. next available TRACK and SECTOR.  So,
  185.  
  186. just by resetting your TRACK and
  187.  
  188. SECTOR numbers to these two values,
  189.  
  190. you can attempt to put your DATA in
  191.  
  192. the next available place.
  193.  
  194.  
  195. ------- continued in PART 16 ---------
  196.